package org.urchr.beorganized.api.impl;

import org.urchr.beorganized.api.base.Log;
import org.urchr.beorganized.api.base.PrivateBaseAPIServlet;
import org.urchr.beorganized.dao.XMLDocumentBuilder;
import org.urchr.beorganized.dao.errors.DBErrorException;
import org.urchr.beorganized.dao.errors.GeneralException;

public class CheckSaveResult extends PrivateBaseAPIServlet{

	@Override
	protected void doProcessPrivate() throws GeneralException {
//		Log.debug(this, "Requesting result: "+getParameter("rnd"));
		Object result = SaveNote.results.get(getParameter("rnd"));
		if(result==null)
			throw new DBErrorException();
		SaveNote.results.remove(getParameter("rnd"));
		if(result instanceof GeneralException)
			throw (GeneralException)result;
		XMLDocumentBuilder doc = new XMLDocumentBuilder();
		doc.getRootElement("note").setAttribute("id", result.toString());
		sendNode(doc.getRootElement());
	}

}
